<?
$order_by = $this->input->get("order_by");
$last_days = $this->input->get("last_days");
$catid = $this->input->get("catid");
?>
<form action="./videos" method="GET" class="videos">
    <div class="videos_categorias">
        <div class="sort">
            <div class="sort1">
                <div class="title">
                    <h3>POR RELEVANCIA</h3>
                </div>
                <div class="list-category">
                    <ul column="order_by">
                        <li key="publish_up" class="<?= (empty($order_by) or $order_by == "publish_up") ? "selected" : "" ?>">Todos</li>
                        <li key="search" class="<?= ($order_by == "search") ? "selected" : "" ?>">Más Buscados</li>
                        <li key="hits" class="<?= ($order_by == "hits") ? "selected" : "" ?>">Más Vistos</li>
                    </ul>
                </div>
            </div>
            <div class="sort2">
                <div class="title">
                    <h3>FECHA</h3>
                </div>
                <div class="list-category">
                    <ul column="last_days">
                        <li key="0" class="<?= (empty($last_days) or $last_days == "0") ? "selected" : "" ?>">Todos</li>
                        <li key="1" class="<?= ($last_days == "1") ? "selected" : "" ?>">Hoy</li>
                        <li key="7" class="<?= ($last_days == "7") ? "selected" : "" ?>">Esta Semana</li>
                        <li key="30" class="<?= ($last_days == "30") ? "selected" : "" ?>">Este Mes</li>
                    </ul>
                </div>
            </div>	


        </div>
        <div class="category">
            <div class="title">
                <h3>CATEGORÍAS</h3>
            </div>
            <div class="list-category">
                <ul column="catid">

                    <li key="0" class="<?= (empty($catid) or $catid == "0") ? "selected" : "" ?>">Todos</li>
                    <?
                    foreach ($categorias as $categoria) {
                        $class = "class=''";

                        if ($catid == $categoria->catid)
                            $class = "class='selected'";

                        echo '<li key="' . $categoria->catid . '" ' . $class . '>' . $categoria->category . '</li>';
                    }
                    ?>	

                </ul>
            </div>

        </div>
    </div>
</form>


<script type="text/javascript">
    head.ready(function(){
	
        (function(){
            // This must be applied to a form (or an object inside a form).
            jQuery.fn.addHidden = function (name, value) {
                return this.each(function () {
                    var input = $(':input[type="hidden"][name="'+name+'"]');
			
                    if(input.length > 0)
                        input.val(value);
                    else
                    {
                        var input = $("<input>").attr("type", "hidden").attr("name", name).val(value);
                        $(this).append($(input));
                    }
	
                });
            };
		
            $(".videos ul li.selected").each(function(){
                var me = $(this);
                var ul = me.closest("ul");
			
                $(".videos").addHidden(ul.attr("column"), me.attr("key"));
            });
		
            $(".videos ul li").click(function(){
                var me = $(this);
                var ul = me.closest("ul");
	
                $(".videos").addHidden(ul.attr("column"), me.attr("key"));
                $(".videos").submit();
            });
        })();

    });

</script>
